package com.example.hao.contentprovider_demo;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MySQL extends SQLiteOpenHelper {

    private static final String DB_NAME = "abc";
    private static final int DB_VERSION = 1;


    public MySQL(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    private static final String TAG = "MySQL";
    /**
     * 表名
     */
    public static final String TABLE_NAME = "student";
    /**
     * 字段名
     */
    private static final String KEY_ID = "_id";
    private static final String KEY_NAME = "_name";
    private static final String KEY_AGE = "_age";
    private static final String KEY_HEIGHT = "_height";
    private static final String KEY_SEX = "_sex";

    @Override
    public void onCreate(SQLiteDatabase db) {
//创建数据表的sql语句
        String sql = " CREATE TABLE " + TABLE_NAME + " ( "
                + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
                + KEY_NAME + " TEXT,"
                + KEY_AGE + " INTEGER,"
                + KEY_SEX + " TEXT,"
                + KEY_HEIGHT + " REAL" + ");";
        Log.d(TAG, "onCreate: " + sql);
//执行sql语句
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }

}
